<?php
class Accountmanager_Model_Accountmanagerdecision implements Accountmanager_Model_Mainable{
    
    private $action_handler;
    private $csrf_token;
    private $get_page_data;
    private $accountmanager_data_getcomments;
    private $accountmanager_data_getcommentdata;
    private $accountmanager_data_getuserimages;
    
    public function main(array $variables = null) {
        switch($variables['get']['page']){
            case "ustawienia-konta":
                return $this->manage_user_account($variables);
                break;
            case "aktualizuj-konto":
                return $this->update_user_account($variables);
                break;
            case "usun-konto":
                return $this->remove_user_account($variables);
                break;
            case 'zarzadzaj-komentarzami':
                return $this->manage_comments($variables);
                break;
            case 'dodaj-komentarz':
                return $this->add_comment($variables);
                break;
            case 'wstaw-komentarz':
                return $this->insert_comment($variables);
                break;
            case 'edytuj-komentarz':
                return $this->edit_comment($variables);
                break;
            case 'aktualizuj-komentarz':
                return $this->update_comment($variables);
                break;
            case 'usun-komentarz':
                return $this->delete_comment($variables);
                break;
            default:
                return $this->default_action($variables);
                break;
        }
    }
    
    private function delete_comment(array $variables = null){
        $this->action_handler = new Accountmanager_Model_Deletecomment;
        return $this->action_handler->main($variables);
    }
    
    private function update_comment(array $variables = null){
        $this->action_handler = new Accountmanager_Model_Updatecomment;
        return $this->action_handler->main($variables);
    }
    
    private function edit_comment(array $variables = null){
        $this->csrf_token = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->csrf_token->main($variables);
        $this->get_page_data = new Pagemanager_Data_Getallpages;
        $page['page'] = $this->get_page_data->main($variables);
        $this->accountmanager_data_getcommentdata = new Accountmanager_Data_Getcommentdata;
        $page['content'] = $this->accountmanager_data_getcommentdata->main($variables);
        $page['template'] = WEB_ROOT_FOLDER."accountmanager/views/addcomment.php";
        return $page;
    }
    
    private function insert_comment(array $variables = null){
        $this->action_handler = new Accountmanager_Model_Insertcomment;
        return $this->action_handler->main($variables);
    }
    
    private function add_comment(array $variables = null){
        $this->csrf_token = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->csrf_token->main($variables);
        $this->get_page_data = new Pagemanager_Data_Getallpages;
        $page['page'] = $this->get_page_data->main($variables);
        $page['template'] = WEB_ROOT_FOLDER."accountmanager/views/addcomment.php";
        return $page;
    }
    
    private function manage_comments(array $variables = null){
        $this->csrf_token = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->csrf_token->main($variables);
        $this->accountmanager_data_getcomments = new Accountmanager_Data_Getpagecomments;
        $page['content'] = $this->accountmanager_data_getcomments->main($variables);
        $page['template'] = WEB_ROOT_FOLDER."accountmanager/views/allcomments.php";
        return $page;
        
    }
    
    private function remove_user_account(array $variables = null){
        $this->action_handler = new Accountmanager_Model_Removeaccount;
        return $this->action_handler->main($variables);
    }
    
    private function update_user_account(array $variables = null){
        $this->action_handler = new Accountmanager_Model_Updateaccount;
        return $this->action_handler->main($variables);
    }
    
    private function manage_user_account(array $variables = null){
        $this->action_handler = new Accountmanager_Data_Accountdata;
        $page['content'] = $this->action_handler->main($variables);
        $this->accountmanager_data_getuserimages = new Accountmanager_Data_Getuserimages;
        $page['image'] = $this->accountmanager_data_getuserimages->main($variables);
        $page['template'] = WEB_ROOT_FOLDER."accountmanager/views/manageaccount.php";
        $this->csrf_token = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->csrf_token->main($variables);
        return $page;
    }

    private function default_action(array $variables = null){
        unset($variables);
        $this->action_handler = new Accountmanager_Model_Accountmanager;
        return $this->action_handler->main(null);
    }

}
